import { Component, OnInit, Input } from '@angular/core';
import { AppGlobalService } from '../../shared/service/app-global.service';

@Component({
  selector: 'app-detail',
  templateUrl: './detail.component.html',
  styleUrls: ['./detail.component.scss']
})
export class DetailComponent implements OnInit {

  // 传入数据
  @Input() tagData: any = {};

  constructor(private appGlobalService: AppGlobalService) {
  }

  ngOnInit() {
    // 数据order排序
    this.tagData['columns'] = this.tagData['columns'].sort((a, b) => a.order - b.order);
  }


  /**
   * 跳转编辑页面
   *
   * @memberof DetailComponent
   */
  redirectToEdit() {
    const params = {
      pageId: this.tagData['editButton']['actionElement']['target'],
      params: {
        _id: this.tagData['editButton']['actionElement']['param'][0]['value'],
      },
      sessionId: localStorage.getItem('sessionId')
    };
    this.appGlobalService.goToForward(params);
  }

  /**
   * 时间格式化
   *
   * @param {*} nows 现在时间戳
   * @returns xx年xx月xx日
   * @memberof DetailComponent
   */
  dateFormat(nows) {
    const now = new Date(parseInt(nows, 10));
    const year = now.getFullYear();
    const month = now.getMonth() + 1;
    const date = now.getDate();
    const hour = now.getHours();
    const minute = now.getMinutes();
    const second = now.getSeconds();
    return year + '年' + month + '月' + date + '日';
  }

}
